if (window.require) {
  var ipc = window.require('electron').ipcRenderer;
  var fs = window.require('fs');
}
function readFile(path: string): Promise<string> {
  return new Promise((res, rej) => {
    fs.readFile(path, (err: Error, data: Buffer) => {
      if (err) {
        rej(err);
      }
      res(data.toString());
    });
  });
}

let electron = {
  ipcSend(channel: any, ...args: any[]) {
    ipc.send(channel, args);
  },
  ipcOn(channel: any, listener: any) {
    ipc.on(channel, listener);
  },
  ipcOnce(channel: any, listener: any) {
    ipc.once(channel, listener);
  },
  readFile(path: string): Promise<string> {
    return readFile(path);
  },
  readFileAll(paths: string[]): Promise<string[]> {
    let s = [];
    paths.forEach((e) => {
      s.push(readFile(e));
    });
    return Promise.all(s);
  },
};
export default electron;
